﻿using Enterprise_Set.API.Application.Commands.Week3.WHAllot_CRUD;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Controllers.Week3
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AllotController : ControllerBase
    {
       

        public IMediator mediator { get; set; }
        public ILogger<AllotController> Logger { get; set; }
        private readonly IBaseRepository<dynamic> _baseRepository;

        public AllotController(IMediator mediator, ILogger<AllotController> logger, IBaseRepository<dynamic> baseRepository)
        {
            this.mediator = mediator;
            Logger = logger;
            _baseRepository = baseRepository;
        }

        /// <summary>
        /// 获取所有仓库
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> GetAllWarehouseData()
        {
            return await mediator.Send(new WHAllotCommand());
        }
        /// <summary>
        /// 获取入库单信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetStorAgeData(GetStorageCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 新增仓库调拨单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddAllotData(AddAllottDataCommand cmd)
        { 
            return await mediator.Send(cmd);    
        }
        /// <summary>
        /// 显示仓库调拨表数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> ShowAllotData()
        {
            return await mediator.Send(new ShowAllotDataCommand());
        }
        /// <summary>
        /// 报表饼图数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<dynamic> ShowWarehourseData()
        {
            List<dynamic> AllData = new List<dynamic>();
            var sql = "select '入库总数', sum(InventoryInfoNum) from Storage;";
            AllData.Add( _baseRepository.GetAll(sql).First());
            var sql2 = "select '出库总数',sum(Nums) from OutBoundLine;";
            AllData.Add(_baseRepository.GetAll(sql2).First());
            return AllData;
        }
    }
}
